<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>留言板功能</title>
    <style>
        #write{
            margin-bottom:50px;
        }
        
    </style>
</head>
<body>
    <div id="content">
        <div id="write">
            <textarea cols="62" rows="5"></textarea>
            <button>发表</button>
        </div>
        <div id="show">
            <ul>
                <li>
                <span>
                    努力学习，让学习成为一种习惯，让自己变得更加优秀
                </span>
                <button>删除</button>
            </li>
        </ul>

        </div>
    </div>
    <script>
        function delNode(obj){
            let liNode = obj.parentNode
            let ulNode = liNode.parentNode
            ulNode.removeChild(liNode)
        }
        function sendText(){
            //获取文本框输入的内容
            let textDivNode = document.getElementById('write')
            let textareaNode = textDivNode.getElementsByTagName('textarea')[0]
            //div元素节点下的textarea元素节点
            let textareaValue = textareaNode.value
            let liNode = document.createElement('li')
            let pNode = document.createElement('p')
            let contextNode = document.createTextNode(textareaValue)
            pNode.appendChild(contextNode)
            liNode.appendChild(pNode)
            let buttonNodes = document.createElement('button')
            let contentDelNode = document.createTextNode('删除')
            buttonNodes.appendChild(contentDelNode)
            buttonNodes.setAttribute('onclick','delNode(this)')
            liNode.appendChild(buttonNodes)
            let showDivNode = document.getElementById('show')
            let ulNode = document.getElementsByTagName('ul')[0]
            ulNode.appendChild(liNode)
        }

        let write = document.getElementById('write')
        let sendButton = write.getElementsByTagName('button')[0]
        sendButton.setAttribute('onclick','sendText()')

    </script>
</body>
</html>